﻿package  com.devilcat.ws{
	import com.devilcat.ws.Basicws;
	import com.worlize.websocket.*;
	import com.devilcat.dt.Gamedt;
	import com.devilcat.ob.OtherPlayer;
	
	public class OtherPlayerws extends Basicws{
		var mUid:int;
		var player:OtherPlayer;
		public function OtherPlayerws(_uid:int,plr:OtherPlayer) {
			super("iw-protocol");
			mUid=_uid;
			player=plr;
			// constructor code
		}
		public function Update(){
			var pack:Object = new Object();
			pack.uid=mUid;
			pack.action="otherplayer";
			var myJson:String = JSONString(pack);
			websocket.sendUTF(myJson);			
		}
		override function handleWebSocketOpen(event:WebSocketEvent):void
		{
		}
		override function handleWebSocketMessage(event:WebSocketEvent):void
		{
			if (event.message.type === WebSocketMessage.TYPE_UTF8)
			{	
				var obj:Object = JSONObject(event.message.utf8Data)
				//trace("UID "+mUid+" : "+obj[0].status);
				switch(obj[0].status){
					case 0:
						player.Destroy();
						break;
					case 1:
						player.WalkStand();					
						break;
					case 2:
						player.WalkLeft();						
						break;
					case 3:
						player.WalkRight();	
					
						break;
				}
			}
		}

	}
	
}
